package com.ahy231.mapper;

import com.ahy231.dto.FirstMessage;
import com.ahy231.dto.GetMessages;
import com.ahy231.entity.Message;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author ahy231
 * @date 2021/7/28 15:17
 * @description
 */
@Mapper
public interface MessageMapper extends BaseMapper<Message> {

    @Select("SELECT message_id, content, time, `read`, username AS sender, sender_id = #{userId} AS receive " +
            "FROM message m LEFT JOIN `user` u ON m.sender_id = u.user_id " +
            "WHERE ( sender_id = #{selfId} AND receiver_id = #{userId} ) " +
            "OR ( sender_id = #{userId} AND receiver_id = #{selfId} ) " +
            "ORDER BY time DESC")
    List<GetMessages> queryMessages(long selfId, long userId);
}
